/**
 * Course Project for User Interface Programming I, 2011
 * Group 19
 */
package vical.controller;

import java.awt.Window;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * The class To manager the Themes
 * 
 * @author Can & Sadan
 */
public class ThemeManager {

    public class Themes {

        public static final String SYSTEM = "System";
        public static final String METAL = "Metal";
        public static final String MOTIF = "Motif";
    }

    public static boolean setTheme(String themeName) {
        String lookAndFeel = null;

        if (themeName.equals(Themes.METAL)) {
            lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
        } else if (themeName.equals(Themes.SYSTEM)) {
            lookAndFeel = UIManager.getSystemLookAndFeelClassName();
        } else if (themeName.equals(Themes.MOTIF)) {
            lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        }
        try {
            UIManager.setLookAndFeel(lookAndFeel);
        } catch (ClassNotFoundException ex) {
            System.out.println(ex.getLocalizedMessage());
            return false;
        } catch (InstantiationException ex) {
            System.out.println(ex.getLocalizedMessage());
            return false;
        } catch (IllegalAccessException ex) {
            System.out.println(ex.getLocalizedMessage());
            return false;
        } catch (UnsupportedLookAndFeelException ex) {
            System.out.println(ex.getLocalizedMessage());
            return false;
        }

        Window[] windows = Window.getWindows();
        for (Window w : windows) {
            SwingUtilities.updateComponentTreeUI(w);
        }
        return true;
    }
}
